﻿using System;
using System.Windows.Markup;
using System.Windows.Input;

namespace Eniux.Framework.Extensions.MarkupExtensions
{
    /// <summary>
    /// KeyGesture 标记扩展类
    /// </summary>
   public class KeyGestureExtension : MarkupExtension
    {
        // http://www.bryanewert.net/journal/2010/6/8/how-to-use-markupextension-for-a-string-resource-that-define.html

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="gesture">表示手势的字符串，例如：Ctrl+ S.</param>
        public KeyGestureExtension(string gesture)
        {
            var kgc = new KeyGestureConverter();
            this.gesture = kgc.ConvertFromString(gesture) as KeyGesture;
        }

        private KeyGesture gesture;

        /// <summary>
        /// 返回值
        /// </summary>
        /// <param name="service">The service.</param>
        /// <returns></returns>
        public override object ProvideValue(IServiceProvider service)
        {
            return this.gesture;
        }
    }
}
